package com.jinbiao.quasar.config;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import org.sagacity.sqltoy.plugins.IUnifyFieldsHandler;

import java.util.HashMap;
import java.util.Map;

public class UnifyFieldsHandler implements IUnifyFieldsHandler {
    @Override
    public Map<String, Object> createUnifyFields() {
        Map<String,Object> map = new HashMap<>();
        if(!StrUtil.isNullOrUndefined(StpUtil.getTokenValue()))
        map.put("createdBy", StpUtil.getLoginId());
        map.put("createdAt", DateUtil.now());
        if(!StrUtil.isNullOrUndefined(StpUtil.getTokenValue()))
        map.put("updatedBy", StpUtil.getLoginId());
        map.put("updatedAt", DateUtil.now());
        map.put("status", "onOff_on");
        return map;
    }

    @Override
    public Map<String, Object> updateUnifyFields() {
        Map<String,Object> map = new HashMap<>();
        if(!StrUtil.isNullOrUndefined(StpUtil.getTokenValue()))
        map.put("updatedBy", StpUtil.getLoginId());
        map.put("updatedAt", DateUtil.now());
        return map;
    }
}
